﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShevaEngine2GUI.Controls;
using ShevaEngine.Core.Modules.Materials;
using Microsoft.Xna.Framework;
using ShevaEngine2GUI.Styles.Interfaces;

namespace ShevaEngine2GUI.Styles.Default
{
    /// <summary>
    /// Button style.
    /// </summary>
    public class DefaultButtonStyle : IButtonStyle
    {
        /// <summary>Singleton.</summary>
        public static readonly DefaultButtonStyle Instance = new DefaultButtonStyle();

        /// <summary>
        /// Method draws button.
        /// </summary>
        /// <param name="button"></param>
        public void DrawNormally(Button button)
        {
            if (button.BackColor != Color.Transparent)
                ShevaEngine.Core.ShevaEngine.Instance.SpriteBatch.Draw(
                    TextureManager.Instance.WhiteTexture, button.RealLocationSize, button.BackColor);

            if (button.BackgroundImage != null)
                ShevaEngine.Core.ShevaEngine.Instance.SpriteBatch.Draw(button.BackgroundImage, button.RealLocationSize, Color.White);                        

            Vector2 textSize = button.Font.MeasureString(button.Text);
            Vector2 textPosition = Vector2.Zero;

            switch (button.TextAlign)
            {
                case ShevaEngine2GUI.Foundation.ContentAlignment.TopLeft:
                case ShevaEngine2GUI.Foundation.ContentAlignment.TopCenter:
                case ShevaEngine2GUI.Foundation.ContentAlignment.TopRight:
                case ShevaEngine2GUI.Foundation.ContentAlignment.MiddleLeft:
                    throw new NotImplementedException();
                    break;
                case ShevaEngine2GUI.Foundation.ContentAlignment.MiddleCenter:
                    textPosition.X = button.RealLocationSize.X + (button.RealLocationSize.Width - textSize.X) / 2;
                    textPosition.Y = button.RealLocationSize.Y + (button.RealLocationSize.Height - textSize.Y) / 2;
                    break;
                case ShevaEngine2GUI.Foundation.ContentAlignment.MiddleRight:
                case ShevaEngine2GUI.Foundation.ContentAlignment.BottomLeft:
                case ShevaEngine2GUI.Foundation.ContentAlignment.BottomCenter:
                case ShevaEngine2GUI.Foundation.ContentAlignment.BottomRight:
                    throw new NotImplementedException();
                    break;
                default:
                    break;
            }
            
            ShevaEngine.Core.ShevaEngine.Instance.SpriteBatch.DrawString(button.Font, button.Text, textPosition, button.ForeColor);
        }

        /// <summary>
        /// Draws button with mouse over.
        /// </summary>
        /// <param name="button"></param>
        public void DrawMouseOver(Button button)
        {
            if (button.BackColor != Color.Transparent)
                ShevaEngine.Core.ShevaEngine.Instance.SpriteBatch.Draw(
                    TextureManager.Instance.WhiteTexture, button.RealLocationSize, button.BackColor);

            ShevaEngine.Core.ShevaEngine.Instance.SpriteBatch.Draw(
                TextureManager.Instance.WhiteTexture, button.RealLocationSize, Color.YellowGreen);

            Vector2 textSize = button.Font.MeasureString(button.Text);
            Vector2 textPosition = Vector2.Zero;

            switch (button.TextAlign)
            {
                case ShevaEngine2GUI.Foundation.ContentAlignment.TopLeft:
                case ShevaEngine2GUI.Foundation.ContentAlignment.TopCenter:
                case ShevaEngine2GUI.Foundation.ContentAlignment.TopRight:
                case ShevaEngine2GUI.Foundation.ContentAlignment.MiddleLeft:
                    throw new NotImplementedException();                    
                case ShevaEngine2GUI.Foundation.ContentAlignment.MiddleCenter:
                    textPosition.X = button.RealLocationSize.X + (button.RealLocationSize.Width - textSize.X) / 2;
                    textPosition.Y = button.RealLocationSize.Y + (button.RealLocationSize.Height - textSize.Y) / 2;
                    break;
                case ShevaEngine2GUI.Foundation.ContentAlignment.MiddleRight:
                case ShevaEngine2GUI.Foundation.ContentAlignment.BottomLeft:
                case ShevaEngine2GUI.Foundation.ContentAlignment.BottomCenter:
                case ShevaEngine2GUI.Foundation.ContentAlignment.BottomRight:
                    throw new NotImplementedException();                    
                default:
                    break;
            }

            ShevaEngine.Core.ShevaEngine.Instance.SpriteBatch.DrawString(button.Font, button.Text, textPosition, button.ForeColor);
        }
    }
}
